package com.spark.usermusicService.service.impl;

import com.spark.R;
import com.spark.usermusicService.entity.User;
import com.spark.usermusicService.service.LoginService;
import com.spark.usermusicService.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author zhouqichun
 * @version 1.0
 * @date 2021/7/1 - 07 - 01 - 15:36
 * @description 登录模块Service实现
 */
@Service
public class LoginServiceImpl implements LoginService {
    //注入用户表
    @Autowired
    private UserService userService;

    @Override
    public R login(User user) {
        R r;
        //从数据库中查询用户
        User queryUser = userService.getUserById(user.getId());
        //用户不存在或者密码不正确，返回登录失败
        if (queryUser==null || !queryUser.getPassword().equals(user.getPassword())){
            r = R.error();
            r.setMessage("登录失败");
            return r;
        }
        r = R.ok();
        r.setMessage("登录成功");
        return r;
    }
}
